package cn.nexttec.noteplayer.databases.dao

import androidx.room.Dao
import androidx.room.Insert
import androidx.room.OnConflictStrategy
import androidx.room.Query
import androidx.room.Update
import cn.nexttec.noteplayer.models.NoteFile
import cn.nexttec.noteplayer.models.VideoFileInfo

@Dao
interface NoteDao {

    @Insert(onConflict = OnConflictStrategy.REPLACE)
    fun createNote(noteFile: NoteFile)

    @Update
    fun updateNote(noteFile: NoteFile)

    @Query("SELECT * FROM NoteFile WHERE videoMd5= :md5 LIMIT 1")
    fun getNoteByVideoMd5(md5:String):NoteFile?

    @Query("SELECT * FROM NoteFile ORDER BY updatedAt DESC LIMIT :limit OFFSET :offset")
    fun getNotes(limit:Int ,offset:Int):List<NoteFile>?

    @Query("SELECT * FROM NoteFile WHERE name LIKE '%' || :keyword || '%' COLLATE NOCASE")
    fun search(keyword: String): List<NoteFile>
}